﻿/*
This file is part of Claymore.
Copyright (C) 2009, Fabrice Michellonet (fabrice dot michellonet at gmail dot com)

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
*/

using System.Collections.Generic;
using System.Reflection;

namespace Claymore
{
    /// <summary>
    /// 
    /// </summary>
    public class Config : IClaymoreConfigElement, IViewManagerConfigElement, IPresenterManagerConfigElement
    {

        #region Fields

        private static IViewManager _viewMngr;
        private static IPresenterManager _presenterMngr;

        #endregion

        /// <summary>
        /// Gets the view manager.
        /// </summary>
        /// <returns></returns>
        internal IViewManager GetViewManager()
        {
            return _viewMngr;
        }

        /// <summary>
        /// Sets the view manager.
        /// </summary>
        /// <param name="viewManager">The view manager.</param>
        /// <returns></returns>
        public IClaymoreConfigElement SetViewManager(IViewManager viewManager)
        {
            _viewMngr = viewManager;
            return this;
        }

        /// <summary>
        /// Gets the presenter manager.
        /// </summary>
        /// <value>The presenter manager.</value>
        internal IPresenterManager GetPresenterManager()
        {
            return _presenterMngr;
        }

        /// <summary>
        /// Sets the presenter manager.
        /// </summary>
        /// <param name="presenterManager">The presenter manager.</param>
        /// <returns></returns>
        public IClaymoreConfigElement SetPresenterManager(IPresenterManager presenterManager)
        {
            _presenterMngr = presenterManager;
            return this;
        }

        /// <summary>
        /// Gets the view manager configuration element.
        /// </summary>
        /// <value>The view manager.</value>
        public IViewManagerConfigElement ViewManager
        {
            get { return this; }
        }

        /// <summary>
        /// Gets the presenter manager configuration element.
        /// </summary>
        /// <value>The presenter manager.</value>
        public IPresenterManagerConfigElement PresenterManager
        {
            get { return this; }
        }

        #region IViewManagerConfigElement Members

        /// <summary>
        /// Adds a views assembly.
        /// </summary>
        /// <param name="assembly">The asembly.</param>
        /// <returns></returns>
        public IClaymoreConfigElement AddViewsAssembly(Assembly assembly)
        {
            _viewMngr.AddViewsAssembly(assembly);
            return this;
        }

        /// <summary>
        /// Adds the views assemblies.
        /// </summary>
        /// <param name="assemblies">The asemblies.</param>
        /// <returns></returns>
        public IClaymoreConfigElement AddViewsAssemblies(IEnumerable<Assembly> assemblies)
        {
            foreach (Assembly asm in assemblies)
                _viewMngr.AddViewsAssembly(asm);

            return this;
        }

        #endregion

        #region IPresenterManagerConfigElement Members

        /// <summary>
        /// Adds a presenter assembly.
        /// </summary>
        /// <param name="assembly">The asembly.</param>
        /// <returns></returns>
        public IClaymoreConfigElement AddPresentersAssembly(Assembly assembly)
        {
            _presenterMngr.AddPresentersAssembly(assembly);
            return this;
        }

        /// <summary>
        /// Adds the presenters assemblies.
        /// </summary>
        /// <param name="assemblies">The assemblies.</param>
        /// <returns></returns>
        public IClaymoreConfigElement AddPresentersAssemblies(IEnumerable<Assembly> assemblies)
        {
            foreach (Assembly asm in assemblies)
                _presenterMngr.AddPresentersAssembly(asm);
            return this;
        }

        #endregion
    }
}
